library(cowplot) #combine ggplot graphs in a grid
library(shinydashboard) # Fancy Dashboard
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
## Loading required package: ggplot2
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggmap':
##
## wind
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:httr':
##
## config
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
##
## Attaching package: 'cowplot'
## The following object is masked from 'package:ggmap':
##
## theme_nothing
## The following object is masked from 'package:lubridate':
##
## stamp
Met Eireann CSV files contain a header at the beginning of the file which is not compatible with the main body of the CSV file. As a result, this header section needs to be removed such that the CSV file of the Weather Station can be supplied. Met Eireann provides data: * Daily (, uses abbreviation ‘dly’ at the beginning of file name) * Monthly (, uses abbreviation ‘mly’ at the beginning of file name) For the subject of this project, I have limited this to the daily datasets
#From www.met.ie
#dPth="http://cli.fusio.net/cli/climate_data/webdata/dly1075.csv"
readMetCSV <- function(dPth) {
#dPth='https://cli.fusio.net/cli/climate_data/webdata/dly5602.csv'
#Read www.Met.ie data from file
#Ignore header information
#library(httr)
if(http_status(GET(dPth))$reason=="Not Found") {
return (list("Error",http_status(GET(dPth))$reason))
} else {
f = file(dPth, 'r')
}
i=0
hdrText=""
dfMet=""
#skip all schema rows until the csv header
while ( TRUE ) {
#Read a line at a time
line = readLines(f, n = 1)
#File doesn't have 5 columns in the first 40 rows; exit loop
if(i>40) {
break
}
#If the row contains more than 5 comma's this is the first row of the header file
if (length(strsplit(line,',')[[1]])>5) {
if(i==0){i=1}
dfMet=read.csv(dPth, skip=i)
break #Exit loop
}
hdrText=paste(hdrText,"\n",line) #Capture Header Text for Info
i=i+1
#print(paste(i,hdrText))
}
close(f) #Close file
return(list(hdrText, dfMet))
}
Not all Weather Station CSV files have the same attributes. Some have a different naming convention; where the attribute name is 4 characters long instead of 5; this process tries to standardise the names. The data was further cleaned, such that missing attributes can be added to equivalent dataset with a value of NA.
checkAttributes<-function(dfCSV){
#Hard Coded list of field names (I failed to find a correct list on www.met.ie)
reqFldNms<-list("date", "ind", "maxtp", "ind.1", "mintp", "igmin", "gmin", "ind.2", "rain", "cbl", "wdsp", "ind.3","hm", "ind.4", "ddhm", "ind.5", "hg", "soil", "pe", "evap", "smd_wd", "smd_md", "smd_pd", "glorad", "sun")
for(nm in reqFldNms) {
#Check name does not exist
if(!(nm %in% names(dfCSV))) {
cat(nm," ",!(nm %in% names(dfCSV)),"\n")
#Check is abbreviated name exists
if(!(substr(nm,1,4) %in% names(dfCSV))) {
#Change Column Name
colnames(dfCSV)[which(names(dfCSV) == substr(nm,1,4))] <- nm
} else {
cat(nm, "\n\n")
#Add Column Name
dfCSV[nm]=NA
}
}
}
return(dfCSV)
}
Data in the CSV file was standardised * Dates were handled ** Dates were split into their relevant components * Category fields were created ** Season ** Rain Type
formatMetCSV <- function(dfMet) {
#Read www.Met.ie data from file
dfMet$date1 <- parse_date_time(dfMet$date, orders = "dmy")
dfMet$Year <- as.numeric(substr(dfMet$date1, 1, 4)) #Create Year Field
dfMet$Month <- as.numeric(substr(dfMet$date1, 6, 7)) #Create Month Field
dfMet$Day <- as.numeric(substr(dfMet$date1, 9, 10)) #Create Day Field
dfMet$abbrDay <- format(strptime(dfMet$date, format = "%d-%b-%Y"), '%a') #Create Day abbr. text Field
#Create Season Field
dfMet$Month <- factor(dfMet$Month,
levels = seq(1,12,by=1),
labels = month.name)
dfMet$Season <- dfMet$Month
levels(dfMet$Season) <- list("Winter" = c("December", "January", "February"),
"Spring" = c("March","April","May"),
"Summer" = c("June","July","August"),
"Autumn" = c("September","October","November"))
#Create Category based on Rain, Temp & Pressure Field
dfMet$"rainType"[is.na(dfMet$maxtp) | is.na(dfMet$rain) & is.na(dfMet$rain)] = ''
dfMet$"rainType"[dfMet$maxtp < 4 & dfMet$rain > 2 & dfMet$rain < 4] = 'Frigid Rain'
dfMet$"rainType"[dfMet$maxtp > 4 & dfMet$rain > 4 & dfMet$rain < 8
& dfMet$cbl < summary(dfMet$cbl)[[2]]] = 'Raining Cats & Dogs' #cbl less than 1st Quartile
dfMet$"rainType"[dfMet$mintp > 10 & dfMet$maxtp < 20 & dfMet$rain > 2] = 'Drizzle'
dfMet$"rainType"[dfMet$maxtp > 10 & dfMet$maxtp < 20 & dfMet$rain < 2] = 'Sprinkle'
dfMet$"rainType"[dfMet$maxtp > 20 & dfMet$rain > 0] = 'Soft Rain'
dfMet$"rainType"[dfMet$wdsp > 15.5 & dfMet$rain > 4] = 'Horizontal Rain'
dfMet$"rainType"[dfMet$maxtp > 20] = 'Scorcher'
dfMet$"rainType"[is.na(dfMet$"rainType") & dfMet$rain > 1] = '4 Seasons is one Day'
dfMet$"rainType"[is.na(dfMet$"rainType") & dfMet$rain > 8] = 'A Torrent'
return(dfMet)
}
Function built to display CSV header information (if it exists)
printDsc<- function(dsc){
#If Description is not an empty string print description
if(nchar(dsc[[1]])>1) {
print(strsplit(dsc[[1]],"\n "),sep="\n")
} else {
print("File has no description")
}
}
A list of most active Weather Stations can be found on link. The list of names do not identically correspond to the name values used in the Met Eireann datasets, so they have not been used.
List of Major Weather Events on [www.met.ie]: , this data was copy and pasted to a new csv file “met climate major weather events.csv”"
library(lubridate)
library(dplyr)
#CSV hardcoded from text on page https://www.met.ie/climate/major-weather-events
strmPth="Data/met climate major weather events.csv"
dfMetEvnts=read.csv(strmPth,skip=0)
dfMetEvnts$Date<-parse_date_time(dfMetEvnts$Date, orders="Ymd") #strptime(dfMetEvnts$Date, format = "%Y-%m-%d")
#Get Storms Only
dfMetStrms<-dfMetEvnts %>% filter(substr(Event,1,5)=="Storm")
#Join to Weather Station Data
Data was loaded from CSV stored by www.met.ie on website https://cli.fusio.net/cli/climate_data/webdata/ Basic data cleaning was performed: * New Status Field created A 2^nd dataset was created: * Cork Stations Only * To be used to reduce Development and Demo times
A graphical representation of the Open and Closed as a Histogram and a Map with points for station co-ordinates.
gHst<-ggplot(dfMetStns, aes(County, fill=Status)) +
geom_histogram(bins=30, stat="count") +
theme(axis.text.x=element_text(angle=60, size=8), legend.position="bottom")
## Warning: Ignoring unknown parameters: binwidth, bins, pad
#ggsave("Ireland Weather Stations.png", width=600, height=400, units="mm", plot=gHst)
#gHst
#devtools::install_github("dkahle/ggmap")
#library(ggmap)
#get_googlemap("ireland", zoom = 12) %>% ggmap()
gMp1<-qmplot(Longitude, Latitude, data = dfMetStns, maptype = "toner-lite", color=Status) +
theme(legend.position="bottom")
## Using zoom = 8...
## Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
#ggsave("Ireland Weather Stations.png", width=300, height=400, units="mm", plot=gMpl)
#qmplot(Longitude, Latitude, data = metStn[[2]], maptype = "toner-lite", geom = "density2d", color = I("red"))
plot_grid(gHst, gMp1, nrow=1, align="h") #Unhappy with alignment
Loading Weather data for relevant Stations. Weather Station records were cycled through to investigate the number of attirbutes in each data. For the purposes of this project I have limited the data to only stations: * Cork * Open * 24+ Attributes
#Using Cork Stations as a subset for faster development
for(sNm in unique(dfMetOpenCorkStns$name)) {
stnPth=paste("https://cli.fusio.net/cli/climate_data/webdata/dly", trimws(dfMetOpenCorkStns[["Station.Number"]][dfMetOpenCorkStns["name"]==sNm]),".csv",sep="")
metWthr<- readMetCSV(stnPth)
#If readMetCSV is a string (i.e. empty) Then do nothing #Otherwise is is a dataframe
if(typeof(metWthr[[2]])=="character") {
#print(paste(sNm,":",stnPth,"\n"))
} else {
cat("[",sNm,"] : ",stnPth," [",typeof(metWthr[[2]]),"]\n\t"
, length(names(metWthr[[2]]))," Columns: ", paste(names(metWthr[[2]]), collapse=","),"\n"
#, shape(metWthr[[2]]),"Observations\n"
,sep="")
#Only select weather stations with 24+ attributes
if(length(names(metWthr[[2]]))>=24) {
#Ensure all the attributes are correct
metWthr[[2]]<-checkAttributes(metWthr[[2]])
#Add Station Name to the Dataset
metWthr[[2]]["Station"]<-toupper(sNm)
#Combine all station datasets into all encompassing single set
if(!exists("allStnData")) {
allStnData <- metWthr[[2]]
} else {
allStnData <- allStnData %>%
bind_rows(metWthr[[2]])
}
}
}
}
## [BALLINCURRIG_(Peafield)] : https://cli.fusio.net/cli/climate_data/webdata/dly6204.csv [list]
## 9 Columns: date,ind,rain,ind.1,maxt,ind.2,mint,gmin,soil
## [BALLINEEN_Caherkirky] : https://cli.fusio.net/cli/climate_data/webdata/dly5002.csv [list]
## 9 Columns: date,ind,rain,ind.1,maxt,ind.2,mint,gmin,soil
## [CLOYNE (LISANLEY)] : https://cli.fusio.net/cli/climate_data/webdata/dly6304.csv [list]
## 9 Columns: date,ind,rain,ind.1,maxt,ind.2,mint,gmin,soil
## [Cork_Airport] : https://cli.fusio.net/cli/climate_data/webdata/dly3904.csv [list]
## 25 Columns: date,ind,maxtp,ind.1,mintp,igmin,gmin,ind.2,rain,cbl,wdsp,ind.3,hm,ind.4,ddhm,ind.5,hg,sun,dos,soil,pe,evap,smd_wd,smd_md,smd_pd
## glorad TRUE
## [GLENGARRIFF (Ilnacullin)] : https://cli.fusio.net/cli/climate_data/webdata/dly201.csv [list]
## 9 Columns: date,ind,rain,ind.1,maxt,ind.2,mint,gmin,soil
## [MALLOW_(SpaHouse)] : https://cli.fusio.net/cli/climate_data/webdata/dly7406.csv [list]
## 9 Columns: date,ind,rain,ind.1,maxt,ind.2,mint,gmin,soil
## [MALLOW_Hazelwood] : https://cli.fusio.net/cli/climate_data/webdata/dly706.csv [list]
## 9 Columns: date,ind,rain,ind.1,maxt,ind.2,mint,gmin,soil
## [Moore_Park] : https://cli.fusio.net/cli/climate_data/webdata/dly575.csv [list]
## 24 Columns: date,ind,maxtp,ind.1,mintp,igmin,gmin,ind.2,rain,cbl,wdsp,ind.3,hm,ind.4,ddhm,ind.5,hg,soil,pe,evap,smd_wd,smd_md,smd_pd,glorad
## sun TRUE
## [Roches_Point] : https://cli.fusio.net/cli/climate_data/webdata/dly1075.csv [list]
## 24 Columns: date,ind,maxtp,ind.1,mintp,igmin,gmin,ind.2,rain,cbl,wdsp,ind.3,hm,ind.4,ddhm,ind.5,hg,soil,pe,evap,smd_wd,smd_md,smd_pd,glorad
## sun TRUE
## [SHERKIN ISLAND] : https://cli.fusio.net/cli/climate_data/webdata/dly3402.csv [list]
## 9 Columns: date,ind,rain,ind.1,maxt,ind.2,mint,gmin,soil
## [SherkinIsland] : https://cli.fusio.net/cli/climate_data/webdata/dly775.csv [list]
## 24 Columns: date,ind,maxtp,ind.1,mintp,igmin,gmin,ind.2,rain,cbl,wdsp,ind.3,hm,ind.4,ddhm,ind.5,hg,soil,pe,evap,smd_wd,smd_md,smd_pd,glorad
## sun TRUE
## [UCC] : https://cli.fusio.net/cli/climate_data/webdata/dly7404.csv [list]
## 9 Columns: date,ind,rain,ind.1,maxt,ind.2,mint,gmin,soil
Display information for selected weather stations
#Set Status of Weather Station to show it is in study
dfMetStns$Status[toupper(dfMetStns$name) %in% unique(allStnData$Station)] = "Report"
datatable(dfMetStns,editable=TRUE)
Update Weather Station Histogram and Map to reflect Reportable Weather Stations and display side by side.
dfMetStns$Status[toupper(dfMetStns$name) %in% unique(allStnData$Station)] = "Report"
gMp2<-qmplot(Longitude, Latitude, data = dfMetStns, maptype = "toner-lite", color=Status) +
theme(legend.position="bottom")
## Using zoom = 8...
## Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
plot_grid(gHst, gMp1, gMp2, nrow=1, align="h") #Unhappy with alignment
Map shows longitudes and latitudes of Ireland.
#Attempt to get map of Ireland from Weather Station: Min and Max, Longitude and Latitude values
#irl<-c(top=floor(summary(metStn[[2]]$Longitude)[[1]]*1.05), bottom=ceiling(summary(metStn[[2]]$Longitude)[[6]]/1.05),
# left=ceiling(summary(metStn[[2]]$Latitude)[[1]]/1.05), right=floor(summary(metStn[[2]]$Latitude)[[6]]*1.05))
#irl
irl <- c(left = -11, bottom = 51, right = -5, top = 55.5)
get_stamenmap(irl, zoom = 8, maptype = "toner-lite") %>% ggmap()
## Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
#?get_googlemap("ireland", zoom = 12) %>% ggmap()
# Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
Cork Airport was selected as a good example (25 attributes, data from circa 1965) to perform Report against. #### Format All Selected Weather Station Data
#unique(allStnData$Station) = "CORK_AIRPORT" "MOORE_PARK" "ROCHES_POINT" "SHERKINISLAND"
dfFmtWthr <- formatMetCSV(allStnData %>% filter(Station==unique(allStnData$Station)[1]))
pSes <- ggplot(dfFmtWthr, aes(Year, maxtp, group=Year, fill=Season), na.rm=TRUE) +
geom_boxplot() +
facet_wrap(~Season)
pSes
From this graph there a few other points to summarise: 1. Winter has a lot of outliers spread across the entire range of years. This appears to suggest that cold winter snaps are frequent. 2. The boxplots show a steep dip in temperature around 2010, which corresponds to Major Weather Events 1. 2009 and 2010 were the Coldest winter for almost 50 years 3. Autumn appears to be cooler than Spring 1. With far more outliers in Spring tending to indicate hotter spells and outliers in Autumn to indicate colder spells 4. In general, it is clear Ireland has a temperate climate.
From the boxplot charts, we can see that all seasons appear to be getting warmer. Spring appears to have the most prominent increase in temperature change over the years.
#library(DT)
datatable(dfFmtWthr, options=list(scrollX='400px'))
## Warning in instance$preRenderHook(instance): It seems your data is too big
## for client-side DataTables. You may consider server-side processing: https://
## rstudio.github.io/DT/server.html
Line Graphs of Temperature for using the Minimum, Mean and Maximum by Time in a monthly format (YYYYMM).
dfWthrTemp <- dfFmtWthr %>%
mutate(yrMthDt = as.numeric(sub('-', '', substr(strptime(date, format = "%d-%b-%Y"), 1, 7)))) %>%
group_by(yrMthDt) %>%
summarise(meanTp = mean((maxtp+mintp)/2, na.rm = TRUE), maxTp = max(maxtp, na.rm = TRUE), minTp = min(mintp, na.rm = TRUE), numRcrds = n()) %>%
select(`yrMthDt`, `meanTp`, `maxTp`, `minTp`, `numRcrds`) %>%
arrange(yrMthDt)
#library(ggplot2)
g1 <- ggplot(dfWthrTemp, aes(yrMthDt,minTp)) +
geom_line(aes(y=minTp, colour=minTp)) +
geom_smooth(method="lm", se=F) +
labs(x="", y="Mean Temp (°C)") +
scale_x_continuous(breaks=seq(195000, 202000, 330)) +
theme(axis.text.x =element_text(angle=45))
g2 <- ggplot(dfWthrTemp, aes(yrMthDt,meanTp)) +
geom_line(aes(y=meanTp, colour=meanTp)) +
geom_smooth(method="lm", se=F) +
labs(x="", y="Mean Temp (°C)",colour="Temp") +
scale_x_continuous(breaks=seq(195000, 202000, 330)) +
theme(axis.text.x =element_text(angle=45)) +
scale_color_gradient(low="greenyellow",high="forestgreen")
g3 <- ggplot(dfWthrTemp, aes(yrMthDt,maxTp)) +
geom_line(aes(y=maxTp, colour=maxTp)) +
geom_smooth(method="lm", se=F) +
labs(x="", y="Max Temp (°C)") +
labs(title="Temperature by Year and Month",subtitle="Month in format: YYYYMM") +
scale_x_continuous(breaks=seq(195000, 202000, 330)) +
theme(axis.text.x =element_text(angle=45)) +
scale_color_gradient(low="orange",high="red")
#install.packages("reshape2")
#library(reshape2)
#install.packages("cowplot")
#library(cowplot)
plot_grid(g3,g2,g1,nrow=3,rel_heights=c(2,1.5,1.5))
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'
Using the Summary function, based on the Linear Regression of the above Table lines, should we REJECT or ACCEPT the Null Hypothesis, H0.
lmMinTemp<-summary(lm(minTp ~ yrMthDt, data = dfWthrTemp))
lmMeanTemp<-summary(lm(meanTp ~ yrMthDt, data = dfWthrTemp))
lmMaxTemp<-summary(lm(maxTp ~ yrMthDt, data = dfWthrTemp))
print(paste("The slope of all 3 linear regression lines is positive:",
"\n\tSlope of line lm(Min Temperature ~ Date(YYYYMM)):", substr(as.character(lmMinTemp$coefficients[2,1]),1,8),
"\n\tSlope of line lm(Mean Temperature ~ Date(YYYYMM)):", substr(as.character(lmMeanTemp$coefficients[2,1]),1,8),
"\n\tSlope of line lm(Max Temperature ~ Date(YYYYMM)):", substr(as.character(lmMaxTemp$coefficients[2,1]),1,8)
,"\n\n"))
## [1] "The slope of all 3 linear regression lines is positive: \n\tSlope of line lm(Min Temperature ~ Date(YYYYMM)): 0.000288 \n\tSlope of line lm(Mean Temperature ~ Date(YYYYMM)): 0.000187 \n\tSlope of line lm(Max Temperature ~ Date(YYYYMM)): 0.000191 \n\n"
dispHyp <- function(smryLM, engh, chrg) {
hypTxt<-paste("At a confidence Interval of 95%, there is", engh, "enough evidence to REJECT H~0~, the Null Hypothesis, in favour of the alternative hypothesis ( H~A~); that there is a", chrg, "difference in the mean temperatures.\nAnd", engh, "support the claim, Global warming is", if(chrg==" positive "){" NOT "} else {" "}, "fake news! i.e. Pr(>|t|) = ", smryLM$coefficients[2,4], " for ", attr(smryLM$terms,"term.labels"),"\n\n", sep="")
return(hypTxt)
}
hpoth <- function(smryLM) {
#Does the probability meet the Threshold
if(smryLM$coefficients[2,4] < 0.05) {
sTh = " " #is enough
} else {
sTh = " NOT " #is not enough
}
#Is slope positive or negative
if(smryLM$coefficients[2,1] > 0) {
sSlp = " positive "
} else {
sSlp = " negative "
}
return(dispHyp(smryLM,sTh,sSlp))
}
print(hpoth(lmMinTemp))
## [1] "At a confidence Interval of 95%, there is enough evidence to REJECT H~0~, the Null Hypothesis, in favour of the alternative hypothesis ( H~A~); that there is a positive difference in the mean temperatures.\nAnd support the claim, Global warming is NOT fake news! i.e. Pr(>|t|) = 0.000983200246356254 for yrMthDt\n\n"
print(hpoth(lmMeanTemp))
## [1] "At a confidence Interval of 95%, there is enough evidence to REJECT H~0~, the Null Hypothesis, in favour of the alternative hypothesis ( H~A~); that there is a positive difference in the mean temperatures.\nAnd support the claim, Global warming is NOT fake news! i.e. Pr(>|t|) = 0.0193993717438224 for yrMthDt\n\n"
print(hpoth(lmMaxTemp))
## [1] "At a confidence Interval of 95%, there is NOT enough evidence to REJECT H~0~, the Null Hypothesis, in favour of the alternative hypothesis ( H~A~); that there is a positive difference in the mean temperatures.\nAnd NOT support the claim, Global warming is NOT fake news! i.e. Pr(>|t|) = 0.050230374519696 for yrMthDt\n\n"
Based on the linear regression analysis carried out, it was generally quite easily distinguishable for each of the different weather staions selected and based on the slope of the respective summary statistics that “Climate Change is Real”.
Joining the basic, generated Storm data to the formatted weather data of the selected weather station, based on the respective dates, the data is summarised to reflect the individual storms and the overall mean of warm (summer & autumn) and cool (winter & spring) attributes.
#Join Storms to Station Weather Data
dfStrmStn<-right_join(dfMetStrms, dfFmtWthr, by=c("Date"="date1"))
dfStrmStn<-dfStrmStn %>%
mutate(Event = ifelse(is.na(Event) & (Season=="Winter" | Season=="Spring"),"Normal (Cool)",
ifelse(is.na(Event) & (Season=="Summer" | Season=="Autumn"),"Normal (Warm)",Event)))
#dfStrmStn<-dfStrmStn %>%
# mutate(Event = ifelse(is.na(Event) & Season=="Winter","Normal (Win)",
# ifelse(is.na(Event) & Season=="Spring","Normal (Spr)",
# ifelse(is.na(Event) & Season=="Summer","Normal (Sum)",
# ifelse(is.na(Event) & Season=="Autumn","Normal (Aut)",Event)))))
#Get Mean Weather values for Storm events
eventWthr<-dfStrmStn %>%
#select(Event, maxtp, mintp, rain, cbl, wdsp, hg, glorad) %>%
group_by(Event) %>%
summarise("Max Temp (C)"=mean(maxtp, na.rm=TRUE),
"Min\nTemp (C)"=mean(mintp, na.rm=TRUE),
"Rain (mm)"=mean(rain, na.rm=TRUE),
"Pressure (hpa)"=mean(cbl, na.rm=TRUE),
"Wind\nSpeed (kt)"=mean(wdsp, na.rm=TRUE),
"Highest\nGust (kt)"=mean(hg, na.rm=TRUE),
#"Global Radiation (J/cm sq.)"=mean(glorad, na.rm=TRUE)
)
#is.nan(1/0-1/0)
#Could not remove NaN from Global Radiation field...
#eventWthr %>%
# mutate(`Global Radiation (J/cm sq.)`=
# if(is.nan(eventWthr$`Global Radiation (J/cm sq.)` ) ==TRUE){0}else{eventWthr$`Global Radiation (J/cm sq.)` })
# #"Global Radiation (J/cm sq.)"=if(is.na(glorad)==TRUE){0}else{mean(glorad, na.rm=TRUE)}) #%>%
# #mutate("Global Radiation (J/cm sq.)"=if(is.na("Global Radiation (J/cm sq.)")==TRUE){0}else{"Global Radiation (J/cm sq.)"}) #%>%
dPlt<-ggplot(eventWthr, aes(`Max Temp (C)`, `Rain (mm)`, colour=Event, size=`Pressure (hpa)`)) +
geom_point() +
labs(title='Comparison of Storm Temp, Rain and Pressure')
ggplotly(dPlt)
, see tool tips for attributes
Compare Attributes of each Weather event for similarities and differences using a radar chart. Storm Darwin appears to have occured at a very low pressure and to have brought the most rainfall.
#https://www.rdocumentation.org/packages/ggradar/versions/0.2/topics/ggradar-package
#install.packages("devtools")
#devtools::install_github("ricardo-bion/ggradar", dependencies=TRUE)
#library(ggradar)
#suppressPackageStartupMessages(library(dplyr))
library(scales)
ggWthr<-eventWthr%>%
mutate_each(funs(rescale), -Event)
## Warning: `funs()` is deprecated as of dplyr 0.8.0.
## Please use a list of either functions or lambdas:
##
## # Simple named list:
## list(mean = mean, median = median)
##
## # Auto named with `tibble::lst()`:
## tibble::lst(mean, median)
##
## # Using lambdas
## list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
## Warning: `mutate_each_()` is deprecated as of dplyr 0.7.0.
## Please use `across()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
ggradar(ggWthr
, axis.label.size=3
, group.line.width=1, group.point.size=2
#, plot.title="Storm Attributes to Norm")
, legend.text.size=10) +
labs(title="Major Storm Events",subtitle="Comparison of Storm Attributes to Norm") +
theme(text=element_text(size=10))
#, legend.title="Event Names")
#add_rownames(var="group") %>%
#mutate(eventDate = paste(Event," (",substr(date1,1,10),")",sep="")) %>%
Graph to display the type of Irish rain based on an abitrary selection of attribute ranges.
rTyp<-dfFmtWthr %>%
filter(Year =="2020") %>%
group_by(mintp,rainType) %>%
summarise(totRain=sum(rain))
#ggplot(rTyp,aes(rainType, totRain)) +
# geom_histogram()
rplt<-ggplot(rTyp, aes(mintp, totRain, color=rainType)) +
geom_point()
ggplotly(rplt)
Rain Type was to be incorporated into a Sunburst Chart but I failed to get the following code block to work in countless iterations:
fig <- plot_ly()
fig <- fig %>%
add_trace(
ids = dfMetRain$abbrDay,
labels = dfMetRain$numDays,
parents = dfMetRain$dayRain,
type = 'sunburst',
maxdepth = 2,
domain = list(column = 0)
)
fig
Shiny Dashboard displays 3 Menu Item Pages
Has 2 sub tabs which show data tables for: 1. Weather Stations 2. Storm Events
Displays the Open, Closed & Reported upon Weather Stations
Has 3 sub tabs which show diagrams to be discussed: 1. Box Plot by Season 2. Min, Mean & Max Temp ~ Year
3. Radar plot of Storm Attibutess